package com.chandra.pos.employee.dao;

/* @(#) EmployeeRepository.java
 * Copyright 2013 - 2015 QatarAirways Group. All Rights Reserved.
 *
 * This Software is the proprietary information of QR Group
 * Use is subject to License terms.
 * Created by T4671 on 18/03/2015.
 */


import com.chandra.pos.employee.dao.entity.EmployeeEntity;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

public interface EmployeeRepository extends JpaRepository<EmployeeEntity, Long> {

    public Page<EmployeeEntity> findByFirstNameLike(String query, Pageable pageable);


    public Page<EmployeeEntity> findByFirstNameAndLastName(String firstName, String name, Pageable pageable);

    public EmployeeEntity findByUserName(String userName);

    @Query("SELECT p FROM EmployeeEntity p WHERE p.firstName LIKE %:searchTerm% or  p.lastName LIKE %:searchTerm% or  p.userName LIKE %:searchTerm%")
    public Page<EmployeeEntity> searchByName(@Param("searchTerm") String searchTerm, Pageable pageable);

    public Page<EmployeeEntity> findByFirstNameOrLastNameOrUserNameContainingIgnoreCase(String firstName, String lastName, String userName, Pageable pageable);
}


/*

http://stackoverflow.com/questions/22573428/case-insensitive-query-with-spring-crudrepository

 */
